package com.dr.cmdb.core.filedcheck;

import com.dr.cmdb.core.dto.FiledCheckDto;
import com.dr.cmdb.core.enums.FiledCheckEnum;
import lombok.Data;

/**
 * @ProjectName: cmdb
 * @Package: com.dr.cmdb.application.filedcheck
 * @Description: 字段校验责任链,使用了模板方法模式，责任链模式
 * @Author: duanrui
 * @CreateDate: 2021/3/29 19:25
 * @Version: 1.0
 * <p>
 * Copyright: Copyright (c) 2021
 */
@Data
public abstract class AbstractFiledCheckHandler {

    protected AbstractFiledCheckHandler nextHandler = null;


    public abstract FiledCheckEnum getType();

    /**
     * 检测字段是否符合规范
     */
    public void handler(FiledCheckDto filedCheckDto) {
        //匹配到该类型
        if (filedCheckDto.getCheckEnums().contains(getType())) {
            checkHandler(filedCheckDto);
        }
        if (null == nextHandler) {
            return;
        }
        nextHandler.handler(filedCheckDto);
    }


    /**
     * 子类具体校验
     *
     * @param filedCheckDto
     */
    public abstract void checkHandler(FiledCheckDto filedCheckDto);
}
